package modelo;

import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;
import java.util.Vector;

public class DAODepto extends DAO{
	
	public static Vector listarDeptos() throws Exception {
	        abrirConexao();
	        String SQL = "Select * from TabDepto";
	        Statement stmt = con.createStatement();
	        ResultSet rst = stmt.executeQuery(SQL);

	        Vector depto = new Vector();
	        
	        while (rst.next()) {
	        	Departamento temp = new Departamento();
	        	temp.setId(rst.getInt("codigo"));
	            temp.setDepto(rst.getString("nome"));
	            depto.add(temp);
	            }        
	        rst.close();
	        stmt.close();
	        fecharConexao();
	        return depto;
	    }
	
	// retorna a string com o nome do departamento a partir do codigo
	public static String nomeDepto(int cod) throws Exception  {
		abrirConexao();
		String nomedepto = null;
		
		String SQL = "Select nome from TabDepto where codigo="+cod;
		Statement stmt = con.createStatement();
		ResultSet rst = stmt.executeQuery(SQL);
		
		while ( rst.next() ) {
			nomedepto = rst.getString("nome");
		}
		rst.close();
		stmt.close();
		fecharConexao();
		return nomedepto; 
	}
}
